package com.tywj.panda.travel.details

import android.os.Bundle
import android.view.Gravity
import android.view.WindowManager
import androidx.fragment.app.FragmentManager
import com.tywj.lib.core.common.extension.onClick
import com.tywj.lib.core.common.util.ResourcesUtil
import com.tywj.panda.customer.common.view.dialog.BottomDialog
import com.tywj.panda.travel.R
import kotlinx.android.synthetic.main.travel_tickets_dialog.*


/**
 * 验票成功对话框
 */
class TravelTicketDialog : BottomDialog() {

    companion object {
        const val TAG = "TravelTicketDialog"
    }

    override fun getLayoutID(): Int = R.layout.travel_tickets_dialog

    override fun getGravity(): Int = Gravity.CENTER

    override fun getCancelOutside(): Boolean = false

    private var mVehicleNo = ""
    private var mNum = 0

    private var listener: (() -> Unit)? = null

    override fun getWidth(): Int = WindowManager.LayoutParams.WRAP_CONTENT

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)

        tvVehicleNo.text = String.format(ResourcesUtil.getString(R.string.travel_vehicle_no), mVehicleNo)
        tvNum.text = String.format(ResourcesUtil.getString(R.string.travel_num), mNum)
    }

    override fun initListener() {
        super.initListener()

        tvConfirm.onClick {
            listener?.invoke()
            dismissDialog()
        }

        ivClose.onClick {
            listener?.invoke()
            dismissDialog()
        }
    }

    fun showTicketDialog(fragmentManager: FragmentManager, vehicleNo: String, num: Int) {
        this.mVehicleNo = vehicleNo
        this.mNum = num
        showDialog(fragmentManager)
    }

    fun setListenerConfirm(listener: () -> Unit) {
        this.listener = listener
    }
}